package com.ruoyi.payment.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
import com.ruoyi.payment.domain.PayApiConfig;
import com.ruoyi.payment.service.PayApiConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付api配置控制器
 *
 * @author Administrator
 * @date 2023/03/11
 */
@RestController
@RequestMapping("/pay_config")
@RequiredArgsConstructor
public class PayApiConfigController extends BaseController {

    private final PayApiConfigService payApiConfigService;

    /**
     * 保存
     *
     * @param payApiConfig 支付api配置
     * @return {@link R}<{@link Void}>
     */
    @PostMapping
    @SaCheckPermission
    @RepeatSubmit
    public R<Void> save(@RequestBody PayApiConfig payApiConfig) {
        return toAjax(payApiConfigService.save(payApiConfig));
    }

    /**
     * 修改
     *
     * @param payApiConfig 支付api配置
     * @return {@link R}<{@link Void}>
     */
    @PutMapping
    @SaCheckPermission
    @RepeatSubmit
    public R<Void> update(@RequestBody PayApiConfig payApiConfig) {
        return toAjax(payApiConfigService.updateById(payApiConfig));
    }

    /**
     * 得到支付api配置
     *
     * @return {@link R}
     */
    @GetMapping
    @SaCheckPermission
    public R<PayApiConfig> getPayApiConfig() {
        return R.ok(payApiConfigService.getOne(Wrappers.emptyWrapper()));
    }

}
